﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TKToXML.Models;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;

namespace TKToXML.Persistence.ClassMaps
{
    public class HopDongMap : ClassMapping<HopDong>
    {
        public HopDongMap()
        {
            Table("EDHOPDDONG"); 
            Id(x => x.Id, map => 
            {
                map.Column("Id");
                map.Generator(Generators.GuidComb);
            });
            Property(x => x.SoThamChieu, map => map.Column("So_TC"));
            Property(x => x.LoaiChungTu, map => map.Column("Loai_CT"));
            Property(x => x.NamChungTu, map => map.Column("Nam_CT"));
            Property(x => x.SoChungTu, map => map.Column("So_CT"));
            Property(x => x.NgayChungTu, map => map.Column("Ngay_CT"));
            Property(x => x.NamTK, map => map.Column("Nam_TK"));
            Property(x => x.SoTK, map => map.Column("So_TK"));            
            Property(x => x.SoHopDong, map => map.Column("So_HD"));
            Property(x => x.NgayHopDong, map => map.Column("Ngay_HD"));
            Property(x => x.ThoiHanThanhToan, map => map.Column("ThoiHan_TT"));
            Property(x => x.MaDVKhaiBao, map => map.Column("Ma_DV_KB"));
            Property(x => x.TenDVKhaiBao, map => map.Column("Ten_DV_KB"));                        
            Property(x => x.MaPTTT, map => map.Column("Ma_PTTT"));
            Property(x => x.MaDKGH, map => map.Column("Ma_DK_GH"));
            Property(x => x.DiaDiemGH, map => map.Column("DiaDiem_GH"));
            Property(x => x.MaNguyenTe, map => map.Column("Ma_NT"));
            Property(x => x.TriGiaNguyenTe, map => map.Column("TriGia_NT"));
            Property(x => x.MaDVMuaHang, map => map.Column("Ma_DV_MH"));
            Property(x => x.TenDVMuaHang, map => map.Column("Ten_DV_MH"));
            Property(x => x.MaDVBanHang, map => map.Column("Ma_DV_BH"));
            Property(x => x.TenDVBanHang, map => map.Column("Ten_DV_BH"));
            Property(x => x.NgayNhapMay, map => map.Column("Ngay_NM"));
            Property(x => x.NguoiNhapMay, map => map.Column("Nguoi_NM"));

            //Bag(x => x.HopDongChiTiets, map =>
            //    {
            //        map.Table("EDHOPDDONGCT");
            //        map.Cascade(Cascade.All);
            //    }, 
            //    x => x.OneToMany(hdct => hdct.Class(typeof(HopDongChiTiet))));

            Bag(x => x.HopDongChiTiets, map =>
                {
                    map.Table("EDHOPDDONGCT");
                    map.Key(m => m.Column("HopDongId"));
                    map.Cascade(Cascade.All);
                    map.Inverse(true);
                },
                x => x.OneToMany(map => map.Class(typeof(HopDongChiTiet))));

        }
    }
}
